let mysql = require("mysql");
let result
let connection = mysql.createConnection({
    host:"localhost",
    password:"2869563610",
    port:3306,
    user:"root",
    database:"demo"
});


connection.connect((err)=>{
    if(err){
        console.error("连接失败"+err.stack);
        return
    }
    console.log("连接成功");
});

connection.query("select * from student",(err,result)=>
{
    if(err) {
        console.error("查询出错"+err.message);
        return;
    }
    console.log(result);
})

let sql = 'insert into student values(?,?,?)';
let params = [18,"3你好",18];

connection.query(sql,params,(err, result)=> {
    if(err) {
        console.error("查询出错"+err.message);
        return;
    }
    console.log("插入成功",result);
    const jsonData = JSON.parse(JSON.stringify(result));
    var blob = new Blob([jsonData ], {type: "text/plain;charset=utf-8"}); 
    console.log(blob)
    FileSaver.saveAs(blob, "helloworld.txt");

});

// 4. 关闭连接 关闭冰箱门
connection.end();

